package com.jl.book.util;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.SmsManager;

public class SMSReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(SMSMethod.SMS_SEND_ACTIOIN)){
            try{
                /* android.content.BroadcastReceiver.getResultCode()方法 */
                //Retrieve the current result code, as set by the previous receiver.
                switch (getResultCode()){
                    case Activity.RESULT_OK:
                        ToastUtils.showShort("短信发送成功");
                        break;
                    case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                        ToastUtils.showShort("短信发送失败");
                        break;
                    case SmsManager.RESULT_ERROR_RADIO_OFF:
                        break;
                    case SmsManager.RESULT_ERROR_NULL_PDU:
                        break;
                }
            }catch (Exception e){

            }
        } else if(intent.getAction().equals(SMSMethod.SMS_DELIVERED_ACTION)){
            /* android.content.BroadcastReceiver.getResultCode()方法 */
            switch(getResultCode()){
                case Activity.RESULT_OK:
                    ToastUtils.showShort("短信已送达");
                    break;
                case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                    /* 短信未送达 */
                    ToastUtils.showShort("短信未送达");
                    break;
                case SmsManager.RESULT_ERROR_RADIO_OFF:
                    break;
                case SmsManager.RESULT_ERROR_NULL_PDU:
                    break;
            }
        }
    }
}

